<template>
  <div class="x">
      <div class="demo-input-suffix">
          金额：<el-input size="50px" v-model="price"></el-input>
      </div>
  <div class="span">&nbsp</div>
  <el-radio-group v-model="radio">
  <el-radio :label="3">微信</el-radio>
  <el-radio :label="6">支付宝</el-radio>
  <el-radio :label="9">银行卡</el-radio>
</el-radio-group>
<div class="span">&nbsp</div>
      <template>
          <div class="slip">
              <el-row>
                  <el-button type="success" round @click="paySuccses">确定支付</el-button>
                  <el-button @click="handle" type="primary" round>返回</el-button>
              </el-row>
          </div>
      </template>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name:'BuyLh',
  data () {
    return {
      radio: 3,
      price:18,
      orderData: [],
      resPost:{
        payType:'',
        spend:1,
        userId: JSON.parse(sessionStorage.getItem('user'))===null?'null':JSON.parse(sessionStorage.getItem('user')).id,
      }
    };
  },
  mounted() {
    this.price=this.$route.query.spend;
    // console.log(this.$route.query.spend)
    this.orderData=this.$route.query.orderData;
    // console.log(this.$route.query.orderData)
   // this.$set(this,"orderDate",this.$route.query.orderData)
    console.log(this.orderData)
  },
  methods:{

    paySuccses(){
      if(this.radio==3){
        this.resPost.payType='微信'
      }
      if(this.radio==6){
        this.resPost.payType='支付宝'
      }
      if(this.radio==9){
        this.resPost.payType='银行卡'
      }
//这里发送生成发票请求！！！
      this.resPost.spend=this.price;
     // this.resPost.payType=this.radio;
      axios({
        method: "post",
        url: "http://localhost:8088/pay",
        params: this.resPost
      }).then(resp=>{
        if(resp.data!=''){
          this.$message({
            message: '支付成功！',
            type: 'success'
          });
        }else {
          this.$message({
            message: '支付失败！',
            type: 'warning'
          });
        }
      })
//这里发送生成订单请求！！！
      axios({
        method: "post",
        url: "http://localhost:8088/addOrders",
        data: this.orderData
      }).then(resp=>{
        if(resp.data==true){
          this.$message({
            message: '订单已生效！',
            type: 'success'
          });
        }else {
          this.$message({
            message: '失败！',
            type: 'warning'
          });
        }
      })

      
//返回购物车
      //this.$router.push("/shoppingCart");
      location.replace("http://localhost:8080/#/shoppingCart")
    },




    handle(){
      this.$router.push("/shoppingCart");
    }
  }
}
</script>
<style scoped>
.span {
  margin-bottom: 50px;
}
.x {
      margin: 0px auto;
      position:absolute;
      top: 29%;
      left: 50%;
      width: 25%;
      height: 63%;

  }
</style>